//package com.example.sunming.excel;
//
//import com.emdata.meteorology.commons.data.ResultData;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//import javax.servlet.http.HttpServletResponse;
//import java.io.PrintWriter;
//import java.util.ArrayList;
//import java.util.List;
//
///**
// * @description:
// * @date: 2021/1/13
// * @author: sunming
// */
//@RestController
//@RequestMapping("sm")
//public class ExcelController {
//
//
//    @GetMapping("download")
//    public ResultData download(HttpServletResponse response) {
//        try {
//            // 文件名
//            StringBuilder fileName = new StringBuilder("data");
//            fileName.append(".csv");
//
//            response.setHeader("Content-Type", "application/octet-stream");
//            response.setCharacterEncoding("utf-8");
//            response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
//
//            // 写入csv文件
//            PrintWriter pw = response.getWriter();
//            pw.println("username,age");
//            StringBuilder sb = null;
//            List<ExcelEntity> boList = new ArrayList<>();
//            boList.add(new ExcelEntity("孙铭", 18));
//            boList.add(new ExcelEntity("liuzhou", 22));
//            writeCsv(pw, boList, sb);
//        } catch (Exception e) {
//
//        }
//        return ResultData.success();
//    }
//
//    private void writeCsv(PrintWriter pw, List<ExcelEntity> boList, StringBuilder sb) {
//        for (ExcelEntity bo : boList) {
//            sb = new StringBuilder();
//            sb.append(bo.getUsername()).append(",")
//                    .append(bo.getAge());
//            // 解决乱码
//            pw.write(new String(new byte[]{(byte) 0xEF, (byte) 0xBB, (byte) 0xBF}));
//            pw.println(sb.toString());
//            pw.flush();
//        }
//    }
//}
